#include <stdlib.h>
#include <string.h>
#include "SymbolPool.h"

SymbolPool::SymbolPool()
{
}

SymbolPool::~SymbolPool()
{
  for(u2 i=0;i<names.size();i++) 
    free(names[i]);
}

u2 SymbolPool::addSymbol(const char * name)
{
  char * n=strdup(name);
  u2     l=getSymbol(name);
  if(l!=no_symbol)
    return l;
  if(!n)
    return no_symbol;
  names.push_back(n);
  return names.size()-1;
}

u2 SymbolPool::getSymbol(const char * name)
{
  for(u2 i=0;i<names.size();i++) 
    if(strcmp(name,names[i])==0)
      return i;
  return no_symbol;
}
